package engine.newUi
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.Record;
	import engine.flag.ResourcesPath;
	import engine.logic.login.PlayCDTimerLogic;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.player.MoveAction;
	import engine.tip.TipsMainLogic;
	import engine.ui.MsgTipsLogic;
	import engine.util.FilterUtil;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	import newx.com.config.StaticIni;
	import newx.com.control.text.NxText;
	import newx.com.control.window.NxWindowEvent;

	public class PostRewardLogic
	{
		private static var _self:PostRewardLogic;
		
		private var _ui:PostRewardUI;
		
		private var _model:ModelLocator;
		
		private var _bind:BindManage;
		
		/**任务绑定标识符*/
		private var _bindIndex:int			=	-1;
		
		/**宝箱领取标识符*/
		private var _bindBoxIndex:int		=	-1;
			
		/**悬赏令个数标识*/
		private var _bindCardIndex:int		=	-1;
		
		/**已经完成次数*/
		private var _overCountIndex:int	=	-1;
		
		/**刷新时间*/
		private var _refreshIndex:int		=	-1;
		
		/**刷新次数*/
		private var _refreshCountIndex:int	=	-1;
		
		/**公告牌数组*/
		private var _billBoardArr:Array;
		
		/**宝箱数组*/
		private var _BoxArr:Array;
		
		/**特效数组*/
		private var _effectArr:Array;
		
		/**宝箱领取个数等级*/
		private var _getBoxArr:Array;
		
		/**存放任务星级等级*/
		private var _starLevelArr:Array;
		
		/**已完成特效数组*/
		private var _overMcArr:Array;
		
		/**已完成任务没提交时特效数组*/
		private var _effArr:Array;
		
		private var _taskLogic:TaskLogic;
		
		/**刷新按钮是否可点击*/
		private var _isCanRefresh:Boolean;
		
		/**是否播放特效*/
		//private var _isPlayeffect:Boolean = false;
		//effect_1
		private var _overTime:int;
		
		private var _CDTimeCount:int
		
		/**CD计时器*/
		private var _CDtimer:Timer;
		
		/**刷新标签*/
		private var _refreshFlag:int	=	0;
		
		/**刷新tips是否显示*/
		private var _isshowTips:Boolean =	false;
		
		//private var _tempOverMc:MovieClip;
		
		//private var _isCanclick:Boolean =	true;
		/**完成任务次数***/
		private var _value:uint = 0 ;  
		/**完成总次数**/
		private static const MAX_COUNT:int = 15;
		public function PostRewardLogic()
		{
		}
		
		public static function getInstance():PostRewardLogic
		{
			if(_self == null)
			{
				_self =new PostRewardLogic();
			}
			return _self;
		}
		
		public function  Init():void
		{
			_billBoardArr	=	[];
			_BoxArr			=	[];
			_starLevelArr	=	[];
			_effectArr		=	[ui.effect_0,ui.effect_1,ui.effect_2];
			_overMcArr		=	[ui.over_0,ui.over_1,ui.over_2];
			_effArr			=	[ui.eff_0,ui.eff_1,ui.eff_2];	
			_getBoxArr		=	[15,35,55];
			_CDtimer		=	new Timer(1000);
			_model			=	ModelLocator.getInstance();
			_bind			=	BindManage.getInstance();
			_taskLogic 		= 	new TaskLogic();
			initText();
			InitInfo();
		}
		
		private function InitInfo():void
		{
			initBillBoard();
			if(_bindIndex == -1)
			{
				_bindIndex	=	_bind.BindRecord(_model.scene,"RewardTaskRec",addTaskFun,removeTaskFun);	
			}
			_bind.BindRecord(_model.scene,"Task_Record",updataTaskTrack,updataTaskTrack);
		}
		
		/**
		 * 初始化固定文本 
		 * 
		 */		
		private function initText():void
		{
			var str:String;
			str						=	StaticIni.getSwfLangStr("UIString_1000430");	
			str						=	str.concat("<br>");
			str						+=	StaticIni.getSwfLangStr("UIString_1000431");
			str						=	str.concat("<br>");
			str						+=	StaticIni.getSwfLangStr("UIString_1000432");	
			str						=	str.concat("<br>");
			str						+=	StaticIni.getSwfLangStr("UIString_1000433");	
			ui.leftText.htmlText	=	str;
			ui.refreshBtn.label		=	StaticIni.getSwfLangStr("UIString_1000426");
//			ResourcesPath.getHalfPic(22021059,ui.headClip);
//			ui.headClip.scaleX		=	0.8;
//			ui.headClip.scaleY		=	0.8;
		}
		
		public function BeforeShow():void
		{
			ResourcesPath.getHalfPic(22021059,ui.headClip);
			starlevel();
			//initBillBoard();
			addEvent();
			
			//奖励任务
			if(_bindIndex == -1)
			{
				_bindIndex	=	_bind.BindRecord(_model.scene,"RewardTaskRec",addTaskFun,removeTaskFun);	
			}
			
			//奖励宝箱
			if(_bindBoxIndex == -1)
			{
				_bindBoxIndex	=	_bind.BindProp(_model.scene.Role,"RewardBoxLog",this,"BoxBackFun");	
			}
			
			//悬赏令的个数
			if(_bindCardIndex == -1)
			{
				_bindCardIndex	=	_bind.BindProp(_model.scene.Role,"RewardCard",this,"RewardCardFun");	
			}
			
			//绑定完成次数
			if(_overCountIndex == -1)
			{
				_overCountIndex	=	_bind.BindProp(_model.scene.Role,"PerDayCount",this,"PerDayCountFun");	
			}
			//绑定刷新时间
			if(_refreshIndex == -1)
			{
				_refreshIndex	=	_bind.BindProp(_model.scene.Role,"PreRefreshTime",this,"PreRefreshTimeFun");	
			}
			
			//绑定刷新次数
			if(_refreshCountIndex == -1)
			{
				_refreshCountIndex	=	_bind.BindProp(_model.scene.Role,"RewardRefreshTimes",this,"PreRefreshTimesFun");	
			}
		}
		
		public function AfterHide():void
		{
			_CDtimer.stop();
			ui.timeLab.htmlText	=	"";
			if(_bindIndex != -1)
			{
				_bindIndex	=	_bind.UnbindRecord("RewardTaskRec",_bindIndex);
			}
			
			if(_bindCardIndex != -1)
			{
				_bindCardIndex	=	_bind.UnbindProp(_model.scene.Role,"RewardCard",_bindCardIndex);
			}

			if(_overCountIndex != -1)
			{
				_overCountIndex	=	_bind.UnbindProp(_model.scene.Role,"PerDayCount",_overCountIndex);
			}
			
			if(_bindBoxIndex != -1)
			{
				_bindBoxIndex	=	_bind.UnbindProp(_model.scene.Role,"RewardBoxLog",_bindBoxIndex);
			}
			
			//绑定刷新时间
			if(_refreshIndex != -1)
			{
				_refreshIndex	=	_bind.UnbindProp(_model.scene.Role,"PreRefreshTime",_refreshIndex);
			}
			
			//绑定刷新次数
			if(_refreshCountIndex != -1)
			{
				_refreshCountIndex	=	_bind.UnbindProp(_model.scene.Role,"RewardRefreshTimes",_refreshCountIndex);
			}
		}
		
		
		/**
		 * 任务变化
		 * @param PropertiesName
		 * @param PropertiesValue
		 * @param data
		 * 
		 */		
		public function addTaskFun(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
//			if(_overCountIndex == -1)
//			{
//				_overCountIndex	=	_bind.BindProp(_model.scene.Role,"PerDayCount",this,"PerDayCountFun");	
//			}
			
			//ui.over_0.gotoAndStop(9);
			ui.refreshBtn.enabled	=	false;
			restoreStar(int(PropertiesName));
			var mc:MovieClip		=	_billBoardArr[int(PropertiesName)] as MovieClip;
			var effectMC:MovieClip	=	_effectArr[int(PropertiesName)] as MovieClip;
			var overMC:MovieClip	=	_overMcArr[int(PropertiesName)] as MovieClip;
			var overEff:MovieClip	=	_effArr[int(PropertiesName)] as MovieClip;
			
			//mc.visible			=	true;	
			var txt:TextField		=	mc.getChildByName("txt") as TextField;	
			var txt1:TextField		=	mc.getChildByName("txt1") as TextField;
			var btn:SimpleButton	=	mc.getChildByName("btn") as SimpleButton;
			var str:String	=	StaticIni.getSwfLangStr("Task_Caption" + PropertiesValue[0]);
			txt1.htmlText		=	str;
			//星级
			var starLev:int		=	(PropertiesValue[1]-1) < 0 ? 0:PropertiesValue[1];
			for(var i:int = 0; i < starLev;i++)
			{
				(mc.getChildByName("star_"+i.toString())as MovieClip).gotoAndStop(2);
			}
			mc["data"]			=	PropertiesValue;
			
			ui["taskMc_"+PropertiesName].visible	=	false;
			ui["taskMc_"+PropertiesName].gotoAndStop(1);
//			if(_value>=5)
//			{
//				btn.visible		=	false;
//				txt.visible		=false; 
//			}else
//			{
				btn.visible		=true;
//				txt.visible 	=true; 
//			}
			overEff.visible	=	false;
			overEff.gotoAndStop(1);
			if(PropertiesValue[6]== 1)//已完成
			{				
				txt.htmlText	=	"";
				overMC.visible	=	true;
				btn.visible		=	false
				overMC.gotoAndStop(overMC.totalFrames);
			}
			else
			{
				txt.visible = true ; 
				overMC.visible	=	false;
				//是否接取任务
				if(PropertiesValue[2] == 0)//没接取任务
				{
					txt.htmlText	=	StaticIni.getSwfLangStr("UIString_1000421");
				}
				else
				{
					//任务是否完成
					if(checkTask(PropertiesValue[0]))
					{
						txt.htmlText	=	StaticIni.getSwfLangStr("UIString_1000447");
						overEff.visible	=	true;
						overEff.gotoAndPlay(1);
					}
					else
					{
						txt.htmlText	=	StaticIni.getSwfLangStr("UIString_1000422");
						ui["taskMc_"+PropertiesName].visible	=	true;
						ui["taskMc_"+PropertiesName].gotoAndPlay(1);
						onMousetips(PropertiesValue,checkTask(PropertiesValue[0]));
					}

				}
			}
			var rec:Array		=	_model.scene.GetRecordEx("RewardTaskRec").recArr;
			//检测当前任务是否都已经完成
			//overTaskCount(rec);
			
			ActivitesGroupLogic.getInstance().removeEffect(29);
			for(var j:int = 0; j < rec.length; j++)
			{
				if(rec[j][1] < 5 && rec[j][2] == 0 )
				{
					ui.refreshBtn.enabled	=	true;
				}
				if(checkTask(rec[j][0]) && rec[j][2] == 1)
				{
					ActivitesGroupLogic.getInstance().addEffect(29);
				}
			}
			
			//PropertiesValue[4] 任务类型
			(ui["taskSign_"+PropertiesName] as MovieClip).visible	=	true;
			(ui["taskSign_"+PropertiesName] as MovieClip).gotoAndStop(PropertiesValue[5]);
			
			if(checkTask(PropertiesValue[0]) && PropertiesValue[2] == 1)
			{
				mc["isOver"]	=	true;
			}
			else
			{
				mc["isOver"]	=	false;
			}
			
			if(_refreshFlag == PropertiesValue[0])
			{
				onMousetips(PropertiesValue,checkTask(PropertiesValue[0]));
			}
				
			//检测星级是否有变化	
			if(_starLevelArr[int(PropertiesName)] == PropertiesValue[1])return	
				
			effectMC.visible	=	true;
			effectMC.gotoAndPlay(1);
			effectMC.addFrameScript(effectMC.totalFrames - 1,mcOverHandle)
//			(effectMC.getChildAt(0) as  MovieClip).gotoAndPlay(1);
//			(effectMC.getChildAt(0) as  MovieClip).addFrameScript((effectMC.getChildAt(0) as  MovieClip).totalFrames - 1,mcOverHandle)
			_starLevelArr[int(PropertiesName)]	=	PropertiesValue[1];
		}
		
		/**
		 * 检测任务是否完成 
		 * @param val
		 * @return 
		 * 
		 */		
		private function checkTask(val:int):Boolean
		{
			var arr:Array	=	_model.scene.GetRecordEx("Task_Record").recArr;
			for(var i:int = 0 ; i < arr.length ; i++)
			{
				if(val == arr[i][0] && arr[i][3] == arr[i][4])
				{
					return true;
				}
			}
			return false
		}
		
		/**
		 *特效播完后的操作 
		 * 
		 */		
		private function mcOverHandle():void
		{
			for(var i:int=0;i < 3;i++)
			{
				(_effectArr[i] as MovieClip).visible	=	false;
				(_effectArr[i] as MovieClip).gotoAndStop(1);
			}
		}
		
		public function removeTaskFun(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			
		}
		
		
		
		public function updataTaskTrack(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			var rec:Array		=	_model.scene.GetRecordEx("RewardTaskRec").recArr;
			if(rec == null)return
			for(var j:int = 0; j < rec.length; j++)
			{
				addTaskFun(j.toString(),rec[j],[]);
			}	
				
		}
		
		/**
		 * 添加侦听事件 
		 * 
		 */		
		private function addEvent():void
		{
			ui.refreshBtn.addEventListener(MouseEvent.CLICK,onRefreshHandle);
			ui.refreshBtn.addEventListener(MouseEvent.ROLL_OVER,onRefreshOverHandle);
			ui.refreshBtn.addEventListener(MouseEvent.ROLL_OUT,onMouseOutHandle);
			ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			_CDtimer.addEventListener(TimerEvent.TIMER,CDtimeHandle);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SENDSERVERTIME),getServerTime);
		}
		
		/**
		 * 初始化公告牌 和 宝箱 
		 * 
		 */		
		private function initBillBoard():void
		{
			if(_billBoardArr.length > 0 )return
			var mc:MovieClip;
			var boxMc:MovieClip;
			var txt1:TextField;
			for(var i:int=0; i < 3;i++)
			{
				//公告牌 
				mc	=	ui["mc_"+i] as MovieClip;
				mc["index"]		=	i;	
				_billBoardArr.push(mc);
				mc["txt"].mouseEnabled	=	false
				mc.addEventListener(MouseEvent.ROLL_OVER,onMouseOverHandle);
				mc.addEventListener(MouseEvent.ROLL_OUT,onMouseOutHandle);
				mc.addEventListener(MouseEvent.CLICK,onBtnciClickHandle);
				for(var j:int=0;j < 5;j++)
				{
					(mc["star_"+j] as MovieClip).gotoAndStop(1);
				}
				
				//宝箱
				boxMc	=	ui["Box_"+i] as MovieClip
				boxMc.gotoAndStop(2);
				boxMc["data"]	=	i;
				boxMc.mouseChildren	=false;
				boxMc.addEventListener(MouseEvent.CLICK,boxClickhandle);
				boxMc.addEventListener(MouseEvent.ROLL_OUT,onBxOutHandle);
				boxMc.addEventListener(MouseEvent.ROLL_OVER,onBoxOverHandle);
				_BoxArr.push(boxMc);
				
				(_overMcArr[i] as MovieClip).mouseEnabled	=(_overMcArr[i] as MovieClip).mouseChildren	=false;
				(_effectArr[i] as MovieClip).mouseEnabled	=(_effectArr[i] as MovieClip).mouseChildren	=false;
				(ui["taskSign_"+i] as MovieClip).mouseEnabled	=(ui["taskSign_"+i] as MovieClip).mouseChildren=false;
				(ui["taskMc_"+i] as MovieClip).mouseChildren	=	(ui["taskMc_"+i] as MovieClip).mouseEnabled =false;
				(_effArr[i] as MovieClip).mouseEnabled	=(_effArr[i] as MovieClip).mouseChildren	=false;
				(_effArr[i] as MovieClip).mouseEnabled	=(_effArr[i] as MovieClip).mouseChildren	=false;
				(_effArr[i] as MovieClip).visible	=false;
				(_effArr[i] as MovieClip).gotoAndStop(1);
			
				//初始化特效
				(_effectArr[i] as MovieClip).visible		=	false;
				(_effectArr[i] as MovieClip).gotoAndStop(1);
				(ui["taskSign_"+i] as MovieClip).visible	=	false;
				
				(_overMcArr[i] as MovieClip).gotoAndStop(1);
				(_overMcArr[i] as MovieClip).visible		=	false;		
			}
			
			ui.taskNumLab.visible	=	false;
			ui.taskInfoLab.visible	=	false;	
			ui.titLab.visible		=	false;
		}
		
		/**
		 * 存储星星的等级 
		 * 
		 */		
		private function starlevel():void
		{
			var rec:Array	=	_model.scene.GetRecordEx("RewardTaskRec").recArr;
			for(var j:int = 0; j < rec.length; j++)
			{
				_starLevelArr.push(rec[j][1]);
			}
		}
		
		/**
		 * 鼠标经过任务表
		 * @param e
		 * 
		 */		
		private function onMouseOverHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.target as MovieClip;
			var arr:Array		=	mc["data"];
			var isover:Boolean	=	mc["isOver"];
			_refreshFlag		=	arr[0];
			mc.gotoAndStop(2);
			onMousetips(arr,isover);
		}
		
		/**
		 * 1 任务ID
		 * 2 星级
		 * 3 是否承接 0,1（已承接）
		 * 4 
		 * 5 任务类型
		 * 6 任务是否完成
		 *  
		 * @param arr isover(次任务是否完成)
		 * 
		 */		
		private function onMousetips(arr:Array,isover:Boolean):void
		{
			if(arr == null)return;
			if(arr[0] == 0) return;
			ui.taskInfoLab.visible	=	true;	
			ui.titLab.visible		=	true;
			// 任务要求 
			var taskSummar:String		=	StaticIni.getSwfLangStr("Task_Summar" + arr[0]);
			var scheduleStr:String		=	TaskTrackingUI.getInstance().getTaskProgress(arr[0]);
			//奖励的声望和钱
			var prizeStr:String			=	StaticIni.getIniVar("taskprize_"+arr[0],"exploit");
			var moneyStr:String			=	StaticIni.getIniVar("taskprize_"+arr[0],"repute");	
			
			//奖牌个数
			var rewardStr:String		=	StaticIni.getIniVar("taskprize_"+arr[0],"rewardcard");
			
			//奖励体力
			var sp:String				=  StaticIni.getIniVar("taskprize_"+arr[0],"SP");
			//任务是否接取
			if(arr[2] == 1)
			{
				//任务是否完成
				if(arr[6] == 1)
				{
					ui.taskNumLab.visible	=	false;
				}
				else
				{
					ui.taskNumLab.visible	=	true;
					ui.taskNumLab.htmlText	=	StaticIni.getSwfLangStr("UIString_1000424")+"："
													+scheduleStr;//任务进度
				}	
			}
			else
			{
				ui.taskNumLab.visible	=	false;	
			}
			
			//任务要气
			ui.taskInfoLab.htmlText		=	StaticIni.getSwfLangStr("UIString_1000423")+"："
												+StaticIni.getSwfLangStr(taskSummar);
			
			ui.titLab.htmlText			=	StaticIni.getSwfLangStrVar("UIString_1000425",
												 [int(prizeStr)*arr[1],int(moneyStr)*arr[1],int(rewardStr)*arr[1],sp]);	
		}
		
		/**
		 * 判断 按钮是 接取 放弃 提交 完成四种状态
		 * @param arr
		 * @param isover
		 * 
		 */		
		private function btnType(arr:Array,isover:Boolean):void
		{
			
		}
		/**
		 * 刷新按钮tips 
		 * @param e
		 * 
		 */		
		private function onRefreshOverHandle(e:MouseEvent = null):void
		{
			if(e != null)
			{
				_isshowTips		=	true;
			}
			if(!_isshowTips)return
			var times:int 	= 	_model.scene.Role.GetProperties("RewardRefreshTimes");
			var money:int;
			if(times < 4)
			{
				money	=	(times+1) * 2;
			}
			else
			{
				money 	=	10;
			}
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000436",[money])
			TipsMainLogic.instance.showString(str);	
		}
		
		/**
		 * BOX tips 
		 * @param e
		 * 
		 */			
		private function onBoxOverHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.target as MovieClip;
			var index:int		=	mc["data"] + 1;
			if(mc.currentFrame == 4)
			{
				//TipsManage.showTips("yikaiqi")
			}
			if(mc.currentFrame == 2)
			{	
				mc.gotoAndStop(3);
				var level:int 			= _model.scene.Role.getPlayerLevel();
				var score:int 			= int(StaticIni.getIniVar("PostReward_" + index, "Count"));
				var _index:int			= compareLevel(index, level);
				var num:String 			= StaticIni.getIniVar("PostReward_" + index, "Reward_" + _index).split(",")[0];
				var rewardStr:String 	= StaticIni.getIniVar("PostReward_" + index, "Reward_" + _index).split(",")[1];
				var str:String = "";
				if(index != 1){
					str = StaticIni.getSwfLangStrVar("UIString_1000696", [num,StaticIni.getSwfLangStr(rewardStr), score]);
				} else {
					str	= StaticIni.getSwfLangStrVar("UIString_1000696", [ StaticIni.getSwfLangStr(rewardStr),("x" +num), score]);
				}
				TipsMainLogic.instance.showString(StaticIni.getSwfLangStr(str));
			}	
		}
		
		/**
		 *获得对应等级 
		 * @param index
		 * @param lvl
		 * @return 
		 * 
		 */		
		private function compareLevel(index:int, lvl:int):int
		{
			var lv:int = int(StaticIni.getIniVar("PostReward_" + index, "Rcount"));
			for(var i:int = 1; i <= lv; i++){
				var interval:Array = StaticIni.getIniVar("PostReward_" + index, "Lv_" + i).split(",");
				if(lvl >= interval[0] && lvl <= interval[1]){
					return i;
				}
			}
			return -1;
		}
		
		/**
		 * 鼠标out
		 * @param e
		 * 
		 */		
		private function onMouseOutHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.target as MovieClip;
			if(mc != null)
			{
				mc.gotoAndStop(1);
			}
			_isshowTips		=	false;	
			TipsMainLogic.instance.hide();
		}
		
		/**
		 * box鼠标out
		 * @param e
		 * 
		 */		
		private function onBxOutHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.target as MovieClip;
			if(mc.currentFrame != 4 )
			{
				mc.gotoAndStop(2);
			}		
			TipsMainLogic.instance.hide();
		}
		
		/**
		 * 任务接取，放弃按钮 
		 * @param e
		 * 
		 */		
		private function onBtnciClickHandle(e:MouseEvent):void
		{
			if(e.target as  MovieClip) return
			
			var mc:MovieClip	=	e.currentTarget as MovieClip;
			var arr:Array		=	mc["data"] as Array;
			var isover:Boolean	=	mc["isOver"];
			var index:int		=	arr[0];
			var overMC:MovieClip	=	_overMcArr[mc["index"]] as MovieClip;	
			
			//已经完成+当前接取的任务
			var getTaskNum:uint	=	_value +getTaskCount();
			
			//是否接取过任务 0(没接过)，1（接过）
			if(arr[2] == 0)
			{
				//接取任务
				if(getTaskNum >= MAX_COUNT)
				{
					NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000487")); 
				}
				else
				{
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ACCEPT_REWARD_TASK,index);
				}			
			}
			else
			{
				if(arr[6] == 0)
				{
					if(isover)
					{
						//任务完成提交任务
						//overMC.addFrameScript(overMC.totalFrames - 1,onOverEndHandle(overMC));
						//if(!_isCanclick)return;
						//_tempOverMc				=	overMC;
						overMC.visible	=	true;
						//_isCanclick		=	false;
						overMC.gotoAndPlay(1);
						overMC.addFrameScript(overMC.totalFrames - 1,
						function():void
						{
							overMC.gotoAndStop(overMC.totalFrames);
						}
						);	
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_COMPLETE_REWARD_TASK,index);
					}
					else
					{
						//放弃任务
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GIVEUP_REWARD_TASK,index);
					}	
				}											
			}	 
		}
		
		/**
		 * 当前接取了多少个任务 
		 * @return 
		 * 
		 */		
		private function getTaskCount():uint
		{
			var rec:Array	=	_model.scene.GetRecordEx("RewardTaskRec").recArr;
			var count:uint	=	0;
			for(var i:int = 0; i < rec.length;i++)
			{
				if(ui["taskMc_"+i].visible	==	false
				    && ui["eff_"+i]	.visible == false )continue//是否有任务完成
				if( rec[i][2] == 1 )
				{
					count++
				}
			}
			return count
		}
		
		/**
		 * 刷新星级 
		 * @param e
		 * 
		 */		
		private function onRefreshHandle(e:MouseEvent):void
		{
			ui.refreshBtn.enabled	=	false;
			//_isPlayeffect 			=	true;
			var rec:Array	=	_model.scene.GetRecordEx("RewardTaskRec").recArr;
			for(var j:int = 0; j < rec.length; j++)
			{
				if(rec[j][1] < 5 && rec[j][2] == 0 )
				{
					ui.refreshBtn.enabled	=	true
				}
			}
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_AFFIRM_CHARGE,20);
		}
		
		/**
		 * 关闭界面 
		 * @param e
		 * 
		 */		
		private function onClickClose(e:NxWindowEvent):void
		{
			ui.showOrHide();
		}
		
		/**
		 * 宝箱点击事件 
		 * @param e
		 * 
		 */		
		private function boxClickhandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.target as MovieClip;
			if(mc.currentFrame == 4	|| mc.filters.length != 0)return
			var index:int 		=	mc["data"] + 1;
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_EXCHANGE_REWARD_BOX,index);
			
			var level:int 			= _model.scene.Role.getPlayerLevel();
			var _index:int			= compareLevel(index, level);
			var num:String 			= StaticIni.getIniVar("PostReward_" + index, "Reward_" + _index).split(",")[0];
			var rewardStr:String 	= StaticIni.getIniVar("PostReward_" + index, "Reward_" + _index).split(",")[1];
			var str:String = "";
			if(index == 1){
				str = StaticIni.getSwfLangStr(rewardStr) + "x" + num;
			} else {
				str	= num + StaticIni.getSwfLangStr(rewardStr);
			}
			//var index:int		=	mc["data"];
			var _tipLogic:MsgTipsLogic = MsgTipsLogic.getRes(mc);
			_tipLogic.showInfo(str);
		}
		
		/**
		 * 宝箱领取状态 
		 * @param str
		 * 
		 */		
		public function set BoxBackFun(str:String):void
		{
			if (str == "")
			{
				for(var j:int=0;j < 3;j++)
				{
					(_BoxArr[j] as MovieClip).filters	=	[];
					(_BoxArr[j] as MovieClip).gotoAndStop(2);
				}
				return
			}
			var arr:Array	=	str.split(",");
			for (var i:int = 0; i < arr.length; i++) 
			{
				if (arr[i] != "")
				{
					(_BoxArr[int(arr[i])-1] as MovieClip).gotoAndStop(4);
					(_BoxArr[int(arr[i])-1]  as MovieClip).mouseChildren =	(_BoxArr[int(arr[i]-1)]  as MovieClip).mouseEnabled =false;	
					(_BoxArr[int(arr[i])-1]  as MovieClip).buttonMode	 =	false;
				}
			}
		}
		
		/**
		 * 绑定悬赏令个数 
		 * @param val
		 * 
		 */		
		public function  set RewardCardFun(val:int):void
		{
			ui.medalNumLab.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000428",[val]);
			var num:int;
			for(var k:int=0;k < 3;k++)
			{
				(_BoxArr[k] as MovieClip).filters	=	[FilterUtil.GrayColorFilter];
			}
			
			//检测现在的奖牌数可以领取那几个档的宝箱
			for (var i:int = 0; i < _getBoxArr.length-1; i++) 
			{
				if(val < _getBoxArr[0])
				{
					num	=	-1;
					break; 
				}
				else
				{
					if(val >= _getBoxArr[_getBoxArr.length -1])
					{
						num	=	_getBoxArr.length;
						break;
					}
					else
					{
						if(val >= _getBoxArr[i] && val < _getBoxArr[i+1])
						{
							num = i+1;
							break;
						}
					}	
				}	
			}
			
			for( var j:int = 0;j < num; j++)
			{
				var boxMc:MovieClip	=	_BoxArr[j] as MovieClip;
				boxMc.filters	=	[];
			}	
		} 
		
		/**
		 * 任务次数
		 * @param int
		 * 
		 */		
		public function set PerDayCountFun(val:int):void
		{
			_value = val;
			var str:String			=	val.toString()+ "/" + MAX_COUNT;
			ui.countLab.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000440",[str]);
			/***/
			var mc:MovieClip; 
			var btn:SimpleButton ; 
			var txt:TextField ; 
			if( val >= MAX_COUNT )
			{
				for(var i:int=0; i < 3;i++)
				{
					//公告牌 
					mc	=	ui["mc_"+i] as MovieClip;
					btn=mc.getChildByName("btn") as SimpleButton;
					txt=mc.getChildByName("txt") as TextField;
					txt.visible =false ; 
					btn.visible =false ; 
				}
				ui.refreshBtn.enabled =false; 
			}
			else
			{
//				for(var j:int=0; j < 3;j++)
//				{
					//公告牌 
//					mc	=	_ui["mc_"+j] as MovieClip;
//					btn=mc.getChildByName("btn") as SimpleButton;
//					txt=mc.getChildByName("txt") as TextField;
//					txt.visible =true ; 
//					btn.visible =true ; 
//				}
			//	ui.refreshBtn.enabled =true; 
			}
		}
		
		/**
		 *  刷新时间
		 * @param int
		 * 
		 */		
		public function set PreRefreshTimeFun(val:int):void
		{
			_overTime	=	val;
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_QUERYSERVERTIME);
		}
		
		/**
		 * 刷新次数 
		 * @param val
		 * 
		 */		
		public function set PreRefreshTimesFun(val:int):void
		{
			onRefreshOverHandle();
		}
		/**
		 * 得到服务器当前时间 
		 * @param e
		 * 
		 */		
		private function getServerTime(e:CustomMsgEvent):void
		{
			var time:int			=	e.pList[0];
			_CDTimeCount		=	_overTime-time;
			if(_CDTimeCount > 0)
			{
				_CDtimer.stop();
				_CDtimer.start();
			}
		}
		
		private function CDtimeHandle(e:TimerEvent = null):void
		{
			_CDTimeCount--;
			var str:String	=	StaticIni.getSwfLangStr("UIString_1000434");
			if(_CDTimeCount <= 0)
			{
				_CDtimer.stop();
				_CDTimeCount	=	0;
			}
			ui.timeLab.htmlText	=	str+PlayCDTimerLogic.getInstance().getTimerStr(_CDTimeCount,true);
		}
		
		/**
		 * 重置星星 
		 * @param val 要重置的公告牌index
		 * 
		 */			
		private function restoreStar(val:int):void
		{
			var mc:MovieClip = _billBoardArr[val] as MovieClip;
			for(var j:int=0;j < 5;j++)
			{
				(mc["star_"+j] as MovieClip).gotoAndStop(1);
			}
		}

		public function get ui():PostRewardUI
		{
			if(_ui==null)
			{
				_ui	=	new PostRewardUI();
			}
			return _ui
		}
	}
}